﻿using System;
using System.Reflection;

namespace Infrastructure.NetExtensions
{
    public static class ObjectExtensions
    {
        public static object GetNonIndexedPropertyValue(this object obj, string property)
        {
            int i = 0;
            PropertyInfo p;
            string[] properties = property.Split('.');
            for (i = 0; i < properties.Length - 1; i++)
            {
                p = obj.GetType().GetProperty(properties[i]);
                obj = p.GetValue(obj, null);
            }
            p = obj.GetType().GetProperty(properties[i]);
            return p.GetValue(obj, null);
        }
    }
}